package com.gitee.wsl.common.ui.symbol

import androidx.compose.ui.graphics.Path
import com.gitee.wsl.common.ui.base.Point
import kotlin.math.sqrt

private val c = -0.5f
private val s = sqrt(3.0f) / 2
private val k = 1 / sqrt(12.0f)
private val a = (k / 2 + 1) * 3

fun Symbol.Companion.wye(position: Point, radius: Float) = Wye(position, radius)

data class Wye(override var position: Point, val radius: Float):LocationSymbol

fun Path.wye(wye: Wye){
    val x0 = wye.radius / 2
    val y0 = wye.radius * k
    val x1 = x0
    val y1 = wye.radius * k + wye.radius
    val x2 = -x1
    val y2 = y1

    moveTo(wye.position.x + x0, wye.position.y + y0)
    lineTo(wye.position.x + x1, wye.position.y + y1)
    lineTo(wye.position.x + x2, wye.position.y + y2)
    lineTo(wye.position.x + (c * x0) - (s * y0),   wye. position.y + (s * x0) + (c * y0))
    lineTo(wye.position.x + (c * x1) - (s * y1),    wye.position.y + (s * x1) + (c * y1))
    lineTo(wye.position.x + (c * x2) - (s * y2),    wye.position.y + (s * x2) + (c * y2))
    lineTo(wye.position.x + (c * x0) + (s * y0),    wye.position.y + (c * y0) - (s * x0))
    lineTo(wye.position.x + (c * x1) + (s * y1),    wye.position.y + (c * y1) - (s * x1))
    lineTo(wye.position.x + (c * x2) + (s * y2),    wye.position.y + (c * y2) - (s * x2))
    close()

}